#ifndef MAX_ALLOWED_SONGS
  #define MAX_ALLOWED_SONGS 300
#endif
#ifndef BPP
  #define BPP               32
#endif
#ifndef MAIN_FPS
  #define MAIN_FPS               60
#endif
// mpeg playback on 32bpp not supported
#if BPP==32
  #ifndef NO_SMPEG
    #define NO_SMPEG
  #endif
#endif
// Transparent shadows are only supported on 32 bpp mode
#if BPP!=32
  #ifndef NO_REFLECTION
    #define NO_REFLECTION
  #endif
#endif
//Dummy print function, only functional when on debug mode
#ifdef DEBUG
  #define dbg_print(msg) say(msg)
#else
  #define dbg_print(msg)
#endif


#ifdef __VERSION__
import "mod_say";
import "mod_key";
import "mod_video";
import "mod_text";
import "mod_proc";
import "mod_file";
import "mod_string";
import "mod_map";
import "mod_timers";
import "mod_dir";
import "mod_wm";
import "mod_draw";
import "mod_screen";
import "mod_regex";
import "mod_sys";
import "mod_rand";
import "mod_time";
import "mod_mouse";
import "mod_sys";
import "mod_math";
#endif

#ifndef NO_SMPEG
import "mpeg";
#endif
import "mod_image";
import "mod_iconv";
import "mod_fmodex";
import "pango";

TYPE songs_list
  string title;
  string artist;
  string dirname;
  string filename;
  string coverpath;
  string bgpath;
  string music_file;
  int cover=0;
End;

CONST
  gamename = "Karaoke";
  song_font = "Droid Sans";  // Font to be used for the text
End;

Global
  string datadir = "./", savegamedir = "", developerpath = gamename;
  string custompath = "HOME";
  float resx = 1024.0, resy=600.0;
  float vresx = 800.0, vresy = 600.0;   //Video resolution
  int desc_file_finished=0, dbid=0, songs_found=0, covers_rendered=0;
  songs_list songs[MAX_ALLOWED_SONGS];
End;

Local
  int die=0;
  float aux=0.0;
End;

include "inc/charset.inc";
include "inc/misc.inc";
include "inc/lyrics.inc";
include "inc/playback.inc";
include "inc/menu.inc";

// This is the main process for the game. It basically sets the resolution
// for you, finds the songs in your songs dir and then tells the menu to appear.
Process main()
Private
  int aux_x=0, aux_y=0;
  int gr_loading=0, gr_proudly_made=0, gr_bennu_logo=0;

Begin
  datadir = cd()+"/";
  developerpath = developerpath+"/";
  if(OS_ID == OS_WIN32)
    custompath = "APPDATA";
  else
    developerpath = "."+developerpath;
  end;
    
  //Start Bennu graphics, set some window vars
  set_fps(MAIN_FPS, 0);
  alpha_steps = 30;
  set_title("Karaoke!");
  rand_seed(time());
  #ifdef NO_MPEG
  restore_type = PARTIAL_RESTORE;   //Faster
  #else
  restore_type = COMPLETE_RESTORE;  //Needed by MPEG
  #endif
  get_desktop_size(&aux_x, &aux_y);
  resx = (float)aux_x; resy = (float)aux_y;
  dbg_print("Trying video mode: "+(int)resx+"x"+(int)resy+"x"+BPP);
  // I cannot set the screen to the desktop resolution
  if(! mode_is_ok(resx, resy, BPP, MODE_FULLSCREEN))
    dbg_print("FATAL ERROR: Sorry, I couldn't set the desktop resolution to "+
        resx+"x"+resy);
    exit();
  end;
#ifdef DEBUG
  resx=640; resy=480;
  set_mode(resx, resy, BPP, MODE_WINDOW);
#else
  set_mode(resx, resy, BPP, MODE_FULLSCREEN);
#endif
  
  // Display a "Loading message" and the Bennu logo
  gr_loading = pango_render('<span font_family="'+song_font+'" weight="bold"'+
    'size="40960" color="#FFFF00">Loading...</span>');
  gr_proudly_made = pango_render('<span font_family="'+song_font+'"'+
    'size="10240" color="#AAAAAA">Proudly made with Bennu</span>');
  gr_bennu_logo = load_image(datadir+"/img/bennugd-logo.jpg");
  
  // Blit the three pre-rendered graphics on the screen
  aux_y = 5*resy/6;
  put(0, gr_bennu_logo, resx/2, aux_y);
  aux_y -= graphic_info(0, gr_bennu_logo, G_HEIGHT)/1.5;
  put(0, gr_proudly_made, resx/2, aux_y);
  aux_y -= 5*graphic_info(0, gr_proudly_made, G_HEIGHT);
  put(0, gr_loading, resx/2, aux_y);
  
  // Unload the graphics, as they're not needed anymore
  unload_map(0, gr_bennu_logo);
  unload_map(0, gr_proudly_made);
  unload_map(0, gr_loading);

  // For some reason, I need to frame twice before the blitted screen appears...
  FRAME; FRAME;
  
  // Look for songs in the songs dir
  find_songs();
  
  // No songs found? Display an error, then quit.
  if (songs_found == 0)
    dbg_print("No songs found in the songs folder, displaying error.");
    no_songs_menu();
    return 0;
  end;
  
  // Start pre-loading the covers, and wait for most of them to load
  pre_render_covers();
  
  // Clear the logos from the screen
  fade(0, 0, 0, 15);
  while(fading)
    FRAME;
  end;

  clear_screen();
  
  fade(100, 100, 100, 15);
  while(fading)
    FRAME;
  end;

  //We've got at least one song, show the normal menu
  //mouse_controller();       // The mouse is not really needed in the menu
  menu();
End;

